package cn.tedu.rabbitmqboot.m3;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Scanner;

@Component
public class Producer {

    @Autowired
    private AmqpTemplate amqpTemplate;

    //需要手动调用，发送消息
    public void send(){
        //convertAndSend 将字符串自动转成byte[] 数组，在发送到 helloworld 队列
        while (true){
            System.out.println("输入：");
            String msg = new Scanner(System.in).nextLine();
            //默认是持久消息
            //如果设置非持久消息 添加第三参数 MessagePostProcessor
            amqpTemplate.convertAndSend("logs","",msg);
        }
    }
}
